package cn.gs.serializable.old;

// @author gs
import cn.gs.util.stream.TokenReader;
import java.io.IOException;
import java.io.Writer;

public class SerialNull implements ISerialEntity {

    @Override
    public Object deserialize() {
        return null;
    }

    @Override
    public <T> T deserialize(Class<T> clazz) {
        return null;
    }

    @Override
    public boolean serialize(Object o) {
        return (o == null);
    }

    @Override
    public void write(Writer writer) throws IOException {
        writer.write("null");
    }

    @Override
    public boolean read(TokenReader reader) throws IOException {
        if ("null".equals(reader.get().toLowerCase())) {
            return true;
        } else {
            reader.back();
            return false;
        }
    }

    @Override
    public String toString(String prefix) {
        return prefix + "null";
    }

    @Override
    public String toString() {
        return toString("");
    }
}
